
update [$BoxTable]
set $MinMax
from [$BoxTable] A join (select * from [$BoxTable]) B on floor(A.leaf/2)=B.leaf and A.stage=B.stage+1
left outer join (select * from [$BoxTable]) C on C.stage=A.stage and A.leaf<>C.leaf and floor(C.leaf/2)=floor(A.leaf/2)
where 
 A.stage=$stage